import React from 'react';
import { Button, message, Row, Col, Modal } from 'antd';
import {
    WeaErrorPage,
    WeaTools,
    WeaDialog,
    WeaRightMenu,
    WeaSearchGroup,
    WeaInput,
    WeaTextarea,
    WeaRichText,
    WeaLocaleProvider
} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
//门户组件
class Signature extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            visible: false,
            title:getLabel(17614,"签字意见"),
            signcontent:''
        }
        this.onShow = this.onShow.bind(this);
        this.onSave = this.onSave.bind(this);
        this.getButtons = this.getButtons.bind(this);
        this.getRightMenu = this.getRightMenu.bind(this);
        this.onRightMenuClick = this.onRightMenuClick.bind(this);
    }
    onShow(){
        this.setState({visible:true});
    }
    onSave(){
        const { signcontent } = this.state;
        if(!signcontent.trim()){
            Modal.error({
                title:  getLabel(15172, '系统提示'),
                content:getLabel(387847, '必要信息不完整，红色星号为必填项！') ,
            });
            return;
        }
    }
    getButtons(){
        let btns = [];
        btns.push(<Button type="primary" onClick={this.onSave}>{getLabel(30986, '保存')}</Button>);
        btns.push(<Button onClick={()=>this.setState({visible:false})}>{getLabel(31129, '取消')}</Button>);
        return btns;
    }
    getRightMenu(){
        let btns = [];
        btns.push({
            icon: <i className='icon-coms-Journal'/>,
            content:getLabel(30986, '保存')
        });
        btns.push({
            icon: <i className='icon-coms-Add-to'/>,
            content:getLabel(31129, '取消')
        });
        return btns
    }
    onRightMenuClick(key){
        switch(key){
            case '1':
                this.onSave();
                break;
            case '2':
                this.setState({visible:false});
                break;
        }
    }
    render() {                                                                                                 
        const { visible, title, signcontent } = this.state;
        let toolbar = [
            {name: 'styles', items: ['Font', 'FontSize']},
            {name: 'colors', items: ['TextColor', 'BGColor']},
            {name: 'basicstyles', items: ['Bold', 'Italic', 'Underline', 'Strike']},
            {name: 'links', items: ['Link', 'Unlink']},
            {name: 'clipboard', items: ['Undo', 'Redo']}
        ];
        return <WeaDialog title={title} 
                  visible={visible}
                  closable={true}
                  onCancel={() => this.setState({visible:false})}
                  icon='icon-coms-portal'
                  iconBgcolor='#1a57a0'
                  maskClosable={false}
                  buttons={this.getButtons()}
                  style={{width:580,height:360}}>
                  <WeaRightMenu datas={this.getRightMenu()} onClick={this.onRightMenuClick}>
                  <WeaRichText
                    ref="WeaRichText"
                    value={signcontent}
                    ckConfig={{
                        toolbar,
                        extraPlugins: 'autogrow',
                        height: 320,
                        autoGrow_minHeight: 320,
                        autoGrow_maxHeight: 320,
                        removePlugins: 'resize',
                        startupFocus: 320,
                    }}
                    bootomBarStyle={{height:'100px'}}
                    onChange={value => {}}
                  />
                  </WeaRightMenu>
            </WeaDialog>
    }
}
class MyErrorHandler extends React.Component {
    render() {
        const hasErrorMsg = this.props.error && this.props.error !== "";
        return ( <WeaErrorPage msg={ hasErrorMsg ? this.props.error :getLabel(385218,"对不起，该页面异常，请联系管理员！")}/>
        );
    }
}
Signature = WeaTools.tryCatch(React, MyErrorHandler, {error: ""})(Signature);
export default Signature;




